Class LogEngine

	Private DIC_TestLogContainer
	Private strLogFilePath
	Private iEventIndex
	private strActionName

	'Class_Initialize
    Private Sub Class_Initialize
		iEventIndex = 0
		Set DIC_TestLogContainer = [new NewDictionary]
		strLogFilePath = CURRENT_REPORT_FOLDER & "\TestLog.xml"
		strActionName = trim(RST_Test_Plan("Testcase Name").value)
    End Sub
	
	'Class_Terminate
    Private Sub Class_Terminate 		
		call GenerateLogSegment()
		Set DIC_TestLogContainer = Nothing
    End Sub

	Private function GenerateLogSegment()
		If DIC_TestLogContainer.count = 0 then exit function
	
		Set xmlDoc = CreateObject("Microsoft.XMLDOM")
		xmlDoc.async = False
		xmlDoc.load(strLogFilePath)

		Set new_Action = xmlDoc.createElement("Action")
		set new_Att_ActionName = xmlDoc.createAttribute("Name")
		new_Att_ActionName.nodeValue = strActionName
		new_Action.setAttributeNode(new_Att_ActionName)

		For i = 0 to DIC_TestLogContainer.count-1
			Set new_Log = xmlDoc.createElement("Log")
			Set new_Att_CurrentTime = xmlDoc.createAttribute("CurrentTime")
			Set new_Att_EventName = xmlDoc.createAttribute("EventName")
			Set new_Att_Status = xmlDoc.createAttribute("Status")
			new_Att_CurrentTime.nodeValue = DIC_TestLogContainer.item(i).item("CurrentTime")
			new_Att_EventName.nodeValue = DIC_TestLogContainer.item(i).item("EventName")
			new_Att_Status.nodeValue = DIC_TestLogContainer.item(i).item("Status")
			new_Log.setAttributeNode(new_Att_CurrentTime)
			new_Log.setAttributeNode(new_Att_EventName)
			new_Log.setAttributeNode(new_Att_Status)
			Set new_Txt_EventContent = xmlDoc.createTextNode(DIC_TestLogContainer.item(i).item("EventContent"))
			new_Log.appendChild(new_Txt_EventContent)
			new_Action.appendChild(new_Log)
		Next

		xmlDoc.getElementsByTagName("TestLog")(0).appendChild(new_Action)
		xmlDoc.save(strLogFilePath)
		Set xmlDoc = Nothing
	End Function

	Public function LogEvent(strStatus,strEventName,strEvenContent)
		Dim dic_event
		set dic_event = CreateObject("Scripting.Dictionary")
		dic_event.Add "CurrentTime",time		
		dic_event.Add "EventName",strEventName
		dic_event.Add "EventContent",strEvenContent
		Select Case ucase(cstr(strStatus))
			Case "PASS","0"
				dic_event.Add "Status","Pass"
			Case "FAIL","1"
				dic_event.Add "Status","Fail"
			Case "WARNING","3"
				dic_event.Add "Status","Warning"
			Case else 
				dic_event.Add "Status","Done"
		End Select
	
		DIC_TestLogContainer.add iEventIndex,dic_event
		iEventIndex = iEventIndex + 1
	End Function

End Class

Function [new TestLogEngine]
	set [new TestLogEngine] = new LogEngine
End function


